﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace SNPAD
{
    public partial class FrmRptSV : Form
    {
        public FrmRptSV()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {


            string values = "select c.pl_desc ,b.model_desc,a.* from hv_sv a inner join jc_model b on a.model_code=b.model_code inner join jc_prodline c on a.pl_code=c.pl_code";
//            string values = @"select c.pl_desc ,m.model_desc, e.pl_code,e.model_code, e.awake_i,e.Current1 ,
//e.Current2,e.Current3,e.Cush_tach_H,e.Cush_tach_M,e.dfc_final,e.dfc_init , e.Noise,e.Noise_M,
//e.P1_07_in_i,e.P1_02_hd,e.P1_07_lo,e.P1_07_oc,e.P1_08_hd,e.P1_1_v,e.P1_13_adc_oc,e.P1_13_adc_oc_1,e.P1_13_adc_oc_1,
//e.P1_13_adc_oc_2,e.P1_13_in_i,e.P1_13_oc,e.P1_2_lkg,e.P1_7_oc,e.P1_8_lkg,e.P1_9_v,e.PCB_Code,e.PCBA_sn,e.PCBA_ver
//, e.Speed1,e.Speed2 ,e.Speed3,e.System_VB_1,e.System_VB_2, e.Remeture,e.TGJudge,
// e.up_05_adc_off,e.up_05_adc_on,e.up_12_adc_off,e.up_12_adc_on,e.up_mon_adc,e.UUT_TEMP,
//e.vibX,e.vibY,e.VibZ,e.X_Vib_H,e.WaveJudge,e.Ver_sn,e.barcode_2d, e.V_Vib_H, e.test_time ,e.judge from HV_SV e
//inner join JC_Model m on e.Model_Code = m.Model_Code  inner join jc_prodline c on e.pl_code=c.pl_code";

            values += " where test_time between '" + dateTimeInput1.Value.ToString("yyyy-MM-dd") + "' and '" + dateTimeInput2.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
            if (cmbModel.SelectedValue.ToString().Trim().Length > 0)
            {
                values += " and a.model_code='" + cmbModel.SelectedValue.ToString() + "'";
            }
            if (cmbPL.SelectedValue.ToString().Trim().Length > 0)
            {
                values += " and e.pl_code='" + cmbPL.SelectedValue.ToString() + "'";
            }
            DataTable dt = OleDbHelper3.ExecuteDataTable(values);

            skinDataGridView3.DataSource = dt;

        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            //Excel.SaveAs(skinDataGridView3);

            Excel.ExportExcel("", skinDataGridView3);
        }

        private void FrmRptSV_Load(object sender, EventArgs e)
        {


            OleDbDataAdapter da = new OleDbDataAdapter();
            System.Data.DataSet ds = new System.Data.DataSet();

            ds.Clear();
            da.SelectCommand = new OleDbCommand("select PL_Code,PL_Desc from jC_prodline", OleDbHelper3.m_conn);
            da.Fill(ds, "Prodline");

            DataRow row = ds.Tables["Prodline"].NewRow();
            row[0] = ""; row[1] = "全部";
            ds.Tables["Prodline"].Rows.Add(row);
            cmbPL.DataSource = ds.Tables[0];
            cmbPL.DisplayMember = ds.Tables[0].Columns[1].Caption; //"PL_Desc";
            cmbPL.ValueMember = ds.Tables[0].Columns[0].Caption; //"PL_Code";
            cmbPL.SelectedIndex = cmbPL.Items.Count - 1;

            OleDbDataAdapter da2 = new OleDbDataAdapter();
            System.Data.DataSet ds2 = new System.Data.DataSet();

            da2.SelectCommand = new OleDbCommand("select model_Code,model_Desc from jC_model", OleDbHelper3.m_conn);
            da2.Fill(ds2, "model");
            DataRow row2 = ds2.Tables["model"].NewRow();
            row2[0] = ""; row2[1] = "全部";
            ds2.Tables["model"].Rows.Add(row2);
            cmbModel.DataSource = ds2.Tables[0];
            cmbModel.DisplayMember = ds2.Tables[0].Columns[1].Caption; //"PL_Desc";
            cmbModel.ValueMember = ds2.Tables[0].Columns[0].Caption; //"PL_Code";
            cmbModel.SelectedIndex = cmbModel.Items.Count - 1;

            //ds=null;
            //row = null;
            //da = null;
            //cmbModel.DataSource = OleDbHelper3.ExecuteDataTable("select * from jC_model");
            //cmbModel.DisplayMember = "model_Desc";
            //cmbModel.ValueMember = "model_Code";

            ////cmbModel.SelectedIndex = 0;
            dateTimeInput2.Value = DateTime.Today;
            dateTimeInput1.Value = DateTime.Today;
        }
    }
}
